//
//  NetworkMonitor.swift
//  ptbuy
//
//  Created by MyMac on 2024/12/2.
//

import SwiftUI	
import Network

// 网络状态监控类
class NetworkMonitor:ObservableObject {
    private let monitor = NWPathMonitor()
    private let queue = DispatchQueue(label: "NetworkMonitor")

    @Published var isConnected: Bool = false
    
    @Published var isShareStatus: Bool = false
    @Published var myFlileName: String = ""
     
    init() {
        monitor.pathUpdateHandler = { [weak self] path in
            guard let self = self else { return }

            // Monitor runs on a background thread so we need to publish
            // on the main thread
            DispatchQueue.main.async {
                if path.status == .satisfied {
                    print("We're connected!")
                    self.isConnected = true
                     

                } else {
                    print("No connection.")
                    self.isConnected = false
                }
            }
        }
        monitor.start(queue: queue)
    }
    
}
